import { defineConfig, loadEnv } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default ({ mode }) => {
  return defineConfig({
    plugins: [
        vue()
    ],
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@import "./src/assets/style/main.scss";'
        }
      }
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
        'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
      }
    },
    // base: `${loadEnv(mode, process.cwd()).VITE_NODE_ENV}` == 'development' ? './' : '/web2/',
    base: '/',
    server: {
      proxy: {
        [`${loadEnv(mode, process.cwd()).VITE_APP_BASE_API}`]: {
          target: loadEnv(mode, process.cwd()).VITE_TEST_HOST, // 线上
          // rewrite: (path:any) => path.replace(/^\/api/, ''),
          changeOrigin: true,
          ws: true
        }
      },
      host: '0.0.0.0',
      open:true, //vite项目启动时自动打开浏览器
    }
  })
}